<?php

namespace App\Http\Controllers\Backend;

use App\DataTables\ChannelOrderReadDataTable;
use App\Http\Requests;
use App\Http\Requests\CreateChannelOrderReadRequest;
use App\Http\Requests\UpdateChannelOrderReadRequest;
use App\Repositories\ChannelOrderReadRepository;
use Flash;
use App\Http\Controllers\AppBaseController;
use Response;

class ChannelOrderReadController extends AppBaseController
{
    /** @var  ChannelOrderReadRepository */
    private $channelOrderReadRepository;

    public function __construct(ChannelOrderReadRepository $channelOrderReadRepo)
    {
        $this->channelOrderReadRepository = $channelOrderReadRepo;
    }

    /**
     * Display a listing of the ChannelOrderRead.
     *
     * @param ChannelOrderReadDataTable $channelOrderReadDataTable
     * @return Response
     */
    public function index(ChannelOrderReadDataTable $channelOrderReadDataTable)
    {
        return $channelOrderReadDataTable->render('backend.channel_order_reads.index');
    }

    /**
     * Show the form for creating a new ChannelOrderRead.
     *
     * @return Response
     */
    public function create()
    {
        return view('backend.channel_order_reads.create');
    }

    /**
     * Store a newly created ChannelOrderRead in storage.
     *
     * @param CreateChannelOrderReadRequest $request
     *
     * @return Response
     */
    public function store(CreateChannelOrderReadRequest $request)
    {
        $input = $request->all();

        $channelOrderRead = $this->channelOrderReadRepository->create($input);

        Flash::success(trans('flash.controller.save_success', ['model' => 'Channel Order Read']));

        return redirect(route('channelOrderReads.index'));
    }

    /**
     * Display the specified ChannelOrderRead.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        $channelOrderRead = $this->channelOrderReadRepository->findWithoutFail($id);

        if (empty($channelOrderRead)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Order Read']));

            return redirect(route('channelOrderReads.index'));
        }

        return view('backend.channel_order_reads.show')->with('channelOrderRead', $channelOrderRead);
    }

    /**
     * Show the form for editing the specified ChannelOrderRead.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function edit($id)
    {
        $channelOrderRead = $this->channelOrderReadRepository->findWithoutFail($id);

        if (empty($channelOrderRead)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Order Read']));

            return redirect(route('channelOrderReads.index'));
        }

        return view('backend.channel_order_reads.edit')->with('channelOrderRead', $channelOrderRead);
    }

    /**
     * Update the specified ChannelOrderRead in storage.
     *
     * @param  int              $id
     * @param UpdateChannelOrderReadRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateChannelOrderReadRequest $request)
    {
        $channelOrderRead = $this->channelOrderReadRepository->findWithoutFail($id);

        if (empty($channelOrderRead)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Order Read']));

            return redirect(route('channelOrderReads.index'));
        }

        $channelOrderRead = $this->channelOrderReadRepository->update($request->all(), $id);

        Flash::success(trans('flash.controller.update_success', ['model' => 'Channel Order Read']));

        return redirect(route('channelOrderReads.index'));
    }

    /**
     * Remove the specified ChannelOrderRead from storage.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        $channelOrderRead = $this->channelOrderReadRepository->findWithoutFail($id);

        if (empty($channelOrderRead)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Order Read']));

            return redirect(route('channelOrderReads.index'));
        }

        $this->channelOrderReadRepository->delete($id);

        Flash::success(trans('flash.controller.delete_success', ['model' => 'Channel Order Read']));

        return redirect(route('channelOrderReads.index'));
    }
}
